package com.lxl.xm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxl.xm.model.entity.AdContent;
import com.lxl.xm.model.entity.Advertiser;
import com.lxl.xm.service.AdContentService;
import com.lxl.xm.mapper.AdContentMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author 86135
* @description 针对表【ad_content(广告内容表)】的数据库操作Service实现
* @createDate 2024-01-31 16:32:41
*/
@Service
public class AdContentServiceImpl extends ServiceImpl<AdContentMapper, AdContent>
    implements AdContentService{
    @Resource
    private AdContentMapper adContentMapper;

    @Override
    public Page<AdContent> getAdContentPage(int current, int size) {
        return adContentMapper.selectAdContentPage(new Page<>(current,size));
    }

    @Override
    public Page<AdContent> getPendingApprovalAds(Page<AdContent> page) {
        QueryWrapper<AdContent>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("approval_status",0);// 0 代表待审核
        Page<AdContent> result = this.page(page,queryWrapper);
        return result;
    }

    @Override
    public boolean createAd(AdContent adContent) {
        Date now = new Date();
        adContent.setSubmitDate(now);
        adContent.setApprovalStatus(0);
        int rowInserted = adContentMapper.insert(adContent);
        return rowInserted == 1;
    }

    @Override
    public Page<AdContent> getAdHistory(Page<AdContent> page, Long advertiserId) {
        QueryWrapper<AdContent>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("advertiser_id",advertiserId);
        return this.page(page,queryWrapper);
    }

    @Override
    public List<Map<String, Object>> getKeywordSearchStatistics(String startDate, String endDate) {
        return this.baseMapper.getKeywordSearchStatistics(startDate,endDate);
    }
    public Integer getCount(){
        return this.baseMapper.getCountofADs();
    }

    @Override
    public Integer getCountOfApply() {
        return this.baseMapper.getCountOfApply();
    }
}




